package com.tedu.mall.controller;

import com.tedu.mall.mapper.AdminMapper;
import com.tedu.mall.pojo.Admin;
import com.tedu.mall.pojo.AdminExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//管理员
@RestController
@CrossOrigin
public class AdminController {
    @Autowired
    AdminMapper adminMapper;
    @RequestMapping("/admin/login")
    //:1314//admin/login?adminName=root
    // &adminPassword=root
    public Admin login(Admin admin){
        AdminExample adminExample=new AdminExample();
        AdminExample.Criteria criteria
                =adminExample.or();
        criteria.andAdminNameEqualTo
                (admin.getAdminName());
        criteria.andAdminPasswordEqualTo
                (admin.getAdminPassword());
        List<Admin> list=adminMapper
                .selectByExample(adminExample);
        if (list!=null && list.size()>=1){
            //登录成功，取出管理员信息
            Admin dbAdmin=list.get(0);
            dbAdmin.setAdminPassword("");
            return dbAdmin;
        }
        //应该返回状态码
        return null;


    }
}
